//
//  MZClosure.swift
//  MZTool
//
//  Created by gby on 2023/2/7.
//

import Foundation


public typealias MZResultClosure = (_ result: Result<MZApiRequest, MZError>) -> Void

public typealias MZResponseClosure = (_ result: Result<MZApiResponse, MZError>) -> Void

public typealias MZRequestSucceedClosure = ((_ response: MZApiResponse) -> Void)

public typealias MZRequestFailureClosure = ((_ failMessage: MZError) -> Void)

public typealias MZProgressBlock = (_ progress: MZProgressResponse) -> Void

public typealias MZRequestResultClosure = (Result<URLRequest, MZError>) -> Void

public typealias MZCompletionClosure = (_ result: Result<MZApiResponse, MZError>) -> Void




public struct MZProgressResponse {

    public let response: MZApiResponse?

    public let progressObject: Progress?

    public init(progress: Progress? = nil, response: MZApiResponse? = nil) {
        self.progressObject = progress
        self.response = response
    }
    public var progress: Double {
        if completed {
            return 1.0
        } else if let progressObject = progressObject, progressObject.totalUnitCount > 0 {
            return progressObject.fractionCompleted
        } else {
            return 0.0
        }
    }
    public var completed: Bool { response != nil }
}
